//mui.init() ! function() {
//	var $target = $('#J_Address');
//
//	$target.citySelect();
//
//	$target.on('click', function(event) {
//		event.stopPropagation();
//		$target.citySelect('open');
//	});
//
//	$target.on('done.ydui.cityselect', function(ret) {
//		$(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
//		$("#provance").val(ret.provance);
//		$("#city").val(ret.city);
//		$("#area").val(ret.area);
//
//	});
//}();
//
//if(GetQueryString('type') == 0) {
//	$("#edit").on('tap', function() {
//		var addressData = JSON.stringify($("#addressform").serializeJson())
//		AjaxPostFn("client/delivery/address/insertinfo", addressData, function(data) {
//			if(data.htmlState.status == '200') {
//				mui.toast('添加地址成功');
//				window.location.href = 'addressList.html'
//			} else {
//				mui.toast('添加失败,请重试!');
//			}
//		})
//	})
//} 


$(function(){
	//判断当前页面是添加新地址还是编辑现有的地址
	if(GetQueryString("type") == 0){
		//添加新地址
		$("#edit").on('tap',function(){
			var addressData = $("#addressform").serializeJson();
			addressData.defaultAddress  = $(".default .mui-switch").hasClass("mui-active") ? '1' : '0';
			addressData.id = 'aaaaa';
			console.log(addressData);
			if($("#consignee").val() == '' || $("#mobile").val() == '' || $("#addressAlias").val() == '' || $("#province").val() == '' || $("#city").val() == '' || $("#county").val() == '' || $("#detailedAddress").val() == ''){
				mui.toast("请填写完整的地址信息。")
			}else{
				MuiAjaxFn("client/delivery/address/insertinfo", addressData, function(data) {
					if(data.htmlState.status == '200') {
						mui.toast('添加地址成功');
						history.go(-1);
					} else {
						mui.toast('添加失败,请重试!');
					}
				})
			}

		})
		
	}else{
		//编辑旧地址
		
	
	}
	
	
	
	
});

(function($, doc) {
	$.init();
	$.ready(function() {
		var cityPicker3 = new $.PopPicker({
			layer: 3
		});
		cityPicker3.setData(cityData3);
		var showCityPickerButton = doc.getElementById('showCityPicker3');
//			var cityResult3 = doc.getElementById('cityResult3');
		var $province = doc.getElementById('province');
		var $city = doc.getElementById('city');
		var $county = doc.getElementById('county');
		showCityPickerButton.addEventListener('tap', function(event) {
			cityPicker3.show(function(items) {
				console.log(items)
				$province.value = (items[0] || {}).text;
				$city.value = (items[1] || {}).text;
				$county.value = (items[2] || {}).text;
				showCityPickerButton.value = (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
//					cityResult3.innerText = "你选择的城市是:" + (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
	});
})(mui, document);